
package com.jims.master.common.utils;

import com.jims.master.modules.doctor.entity.ClinicMaster;
import com.jims.master.modules.doctor.entity.PatVisit;
import com.jims.master.modules.doctor.service.ClinicMasterService;
import com.jims.master.modules.doctor.service.PatVisitService;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.UUID;

/**
 * 号码生成规则
 */
public class NumberUtils {
    private static ClinicMasterService clinicMasterService = SpringContextHolder.getBean(ClinicMasterService.class);
    private static PatVisitService patVisitService = SpringContextHolder.getBean(PatVisitService.class);
    /**
     * 生成病人Id
     * @return
     */
    public static String getPatMasterId() {
        Date date=new Date();
        String strDate=DateUtils.formatDate(date,"yyyyMMddhhmmss");
        String testNo="BR"+strDate+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 获取门诊检查申请号
     * @param clinicId
     * @return
     */
    public static String getClinicInspect(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="JC"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 获取体检检查申请号
     * @param clinicId
     * @return
     */
    public static String getTJClinicInspect(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="TJC"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }
    /**
     * 获取门诊检验申请号
     * @param clinicId
     * @return
     */
    public static String getClinicLab(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="JY"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 获取体检检验申请号
     * @param clinicId
     * @return
     */
    public static String getTJClinicLab(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="TJY"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }
    /**
     * 获取门诊处方申请号
     * @param clinicId
     * @return
     */
    public static String getClinicPrescription(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="CF"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 获取住院处方申请号
     * @param visitId
     * @return
     */
    public static String getVisitPrescription(String visitId) {
        PatVisit patVisit=patVisitService.get(visitId);
        String testNo="CF"+patVisit.getVisitNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 获取门诊用血申请号
     * @param clinicId
     * @return
     */
    public static String getClinicUseBlood(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="YX"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 获取门诊手术申请号
     * @param clinicId
     * @return
     */
    public static String getClinicOperation(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="SS"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }
    /**
     * 获取门诊处置治疗申请号
     * @param clinicId
     * @return
     */
    public static String getClinicTreat(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="CZ"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }
    public static String getTJClinicTreat(String clinicId) {
        ClinicMaster clinicMaster=clinicMasterService.get(clinicId);
        String testNo="TCZ"+clinicMaster.getClinicNo()+(int)(Math.random()*9000);
        return testNo;
    }
    /**
     * 生成门诊收据号--rcptNo
     * @return
     */
    public static String getRcptNo() {
        Date date=new Date();
        String strDate=DateUtils.formatDate(date,"yyyyMMddhhmmss");
        String testNo=strDate+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 提供精确的减法运算。
     * @param v1 被减数
     * @param v2 减数
     * @return 两个参数的差
     * @author fengyg
     */
    public static double sub(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.subtract(b2).doubleValue();
    }

    /**
     * 住院用血申请号
     * @param visitId
     * @return
     */
    public static String getHospUseBlood(String visitId) {
        PatVisit patVisit=patVisitService.get(visitId);
        String testNo="YX"+patVisit.getVisitNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 住院检查
     * @param visitId
     * @return
     */
    public static String getClinicInspectIn(String visitId) {
        PatVisit patVisit=patVisitService.get(visitId);
        String testNo="JC"+patVisit.getVisitNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 预交金序号
     * @param visitId
     * @return
     */
    public static String getVisitPreIn(String visitId) {
        PatVisit patVisit=patVisitService.get(visitId);
        String rcptNo="YJJ"+patVisit.getVisitNo()+(int)(Math.random()*9000);
        return rcptNo;
    }

    /**
     * 预交金退款号
     * @param visitId
     * @return
     * @author CTQ
     * @date 2017-07-20 17:27:23
     */
    public static String getReturnNo(String visitId) {
        PatVisit patVisit=patVisitService.get(visitId);
        String rcptNo="YJJTK"+patVisit.getVisitNo()+(int)(Math.random()*9000);
        return rcptNo;
    }
    /**

     * 发血申请单号
     * @return
     */
    public static String getOutSheet() {
        String testNo = "FX" + (int) (Math.random() * 9000);
        return testNo;
    }
/**
     * 住院检验申请号
     * @param visitId
     * @return
     */
    public static String getClinicLabIn(String visitId) {
        PatVisit patVisit=patVisitService.get(visitId);
        String testNo="JY"+patVisit.getVisitNo()+(int)(Math.random()*9000);
        return testNo;
    }

    /**
     * 一卡通结账序号
     * @return
     */
    public static String getCardAcctNo(){
        Date date=new Date();
        String strDate=DateUtils.formatDate(date,"yyyyMMddhhmmss");
        String testNo=strDate+(int)(Math.random()*9000);
        return "YKT"+testNo;
    }

    /**
     * 获取UUID
     * @return
     */
    public static String  getUUID(){
        UUID uuid = UUID.randomUUID();
        return  uuid.toString();
    }
}
